package cn.t215.cloud.user;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
@EnableDiscoveryClient
//@EnableEurekaClient
@RestController
public class UserServiceApp {
    @Value("${server.port}")
    private int port;

    public static void main(String[] args) {
        SpringApplication.run(UserServiceApp.class, args);
    }

    @GetMapping("")
    public String hello() {
        return "Hello User Service : " + port;
    }

    @GetMapping("/users/search")
    public User users(String name, String password) {
        return new User(111,name,password);
    }
    @GetMapping("/users")
    public List<User> users() {
        List<User> list = new ArrayList<>();
        list.add(new User(1,"暂时","123"));
        list.add(new User(2,"李四","abc"));
        return list;
    }

    @PostMapping("/users")
    public User save(@RequestBody User user) {
        user.setId(3);
        return user;
    }

    @PostMapping("/users2")
    public User save2(User user) {
        user.setId(35);
        return user;
    }
}
